from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC


class Index:
    def __init__(self, driver):
        self.driver = driver
        self.wait = WebDriverWait(self.driver, 10)

    SEARCH_BOX = (By.ID, "chat-textarea")
    SEARCH_BUTTON = (By.ID, "chat-submit-button")
    HOT_SEARCH = (By.CLASS_NAME, "s-hotsearch-wrapper-new-hot")

    def open(self,url):
        self.driver.get(url)

    def enter_search(self,xiaodu):
        xiaodu_field = self.wait.until(
            EC.presence_of_element_located(self.SEARCH_BOX)
        )
        xiaodu_field.clear()
        xiaodu_field.send_keys(xiaodu)

    def click_search(self):
        search_button = self.wait.until(
            EC.presence_of_element_located(self.SEARCH_BUTTON)
        )
        search_button.click()

    def search(self,xiaodu):
        self.enter_search(xiaodu)
        self.click_search()

    def hot_search(self):
        hot_search = self.wait.until(
            EC.presence_of_element_located(self.HOT_SEARCH)
        )
        hot_search.click()

